<template>
    <div>
        <div><h1>品牌列表</h1></div>
        <div>
            <el-table :data="tableData" stripe style="width: 100%">
                <el-table-column prop="brandId" label="ID" width="180" />
                <el-table-column prop="brandName" label="品牌名称" width="180" />
                <el-table-column prop="brandUse" label="使用数量" width="180" />
                <el-table-column prop="brandTop" label="排序" width="180" />
                <el-table-column prop="brandStatus" label="状态" width="180" />
                <el-table-column prop="createTime" label="时间" width="180" />
                <el-table-column prop="address" label="操作" />
            </el-table>
        </div>
        <div style="margin-top: 20px;">
            <el-pagination
                v-model:current-page="searchForm.pageNum"
                v-model:page-size="searchForm.pageSize"
                :page-sizes="[2, 4, 6, 8]"
                :background="true"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
            />
        </div>
    </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { getBrandList } from '../api/api';


const tableData = ref([]);
const searchForm = ref({
    pageNum: 1,
    pageSize: 2
});
const total = ref(0);

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  loadList();
}
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  loadList();
}

const loadList = () => { 
    getBrandList(searchForm.value).then((res:any) => {
        tableData.value = res.data.data.records;
        total.value = res.data.data.total;
    })
};


onMounted(() => {
    loadList();
});


</script>

<style scoped></style>
